/**
 * Copyright @ 2013 - 2015 Suntec Software(Shanghai) Co., Ltd.
 * All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are NOT permitted except as agreed by
 * Suntec Software(Shanghai) Co., Ltd.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 */

#include "QmlPlugin.h"
#include "View/Demo.h"
#include "qmlframework/NQAPI.h"
#include "qmlframework/NQView.h"
#include "qmlframework/NQDivView.h"
#include "qmlframework/NQSideView.h"
#include "qmlframework/NQMainScreen.h"
#include "qmlframework/NQSideScreen.h"
#include <QQmlContext>
#include <QtQml>

QmlPlugin::QmlPlugin(AppId appId, QObject *parent)
    : QObject(parent)
    , m_appId(appId)
{
}

QmlPlugin::~QmlPlugin()
{
}

void QmlPlugin::registerTypes()
{
    // register qml context.
    QQmlContext *ctx = APP::IF(m_appId) ? APP::IF(m_appId)->appQmlContext() : NULL;
    if (ctx) {
        ctx->setContextProperty("APP_LogTag", APP_LogTag);
        ctx->setContextProperty("MIST", APP::MIST(m_appId));
        ctx->setContextProperty("APP", APP::IF(m_appId));
        ctx->setContextProperty("appId", m_appId);
    }

    // framework build in view type, register this view type or
    // the sub-types of NQView defined by developers.
    qmlRegisterType<NQView>("NQViews", 1, 0, "NQView");
    qmlRegisterType<NQDivView>("NQViews", 1, 0, "NQDivView");
    qmlRegisterType<NQSideView>("NQViews", 1, 0, "NQSideView");
    qmlRegisterType<NQMainScreen>("NQViews", 1, 0, "NQMainScreen");
    qmlRegisterType<NQSideScreen>("NQViews", 1, 0, "NQSideScreen");
    qmlRegisterType<Demo>("CustomViews", 1, 0, "Demo");
}

/* EOF */
